export function FoodHold(id, layer, FoodHold) {
    const { x1, x2, y1, y2, prev, next} = FoodHold;
    this.x1 = x1;
    this.x2 = x2;
    this.y1 = y1; // y1 > y2
    this.y2 = y2;
    this.prev = Number(prev);
    this.next = Number(next);
    this.layer = Number(layer);
    this.id = Number(id);
}

FoodHold.prototype.getTop = function() {
    return this.y1 < this.y2? this.y1 : this.y2;
}

FoodHold.prototype.getBottom = function() {
    return this.y1 > this.y2? this.y1 : this.y2;
}

FoodHold.prototype.getLeft= function() {
    return this.x1 < this.x2? this.x1 : this.x2;
}

FoodHold.prototype.getRight= function() {
    return this.x1 > this.x2? this.x1 : this.x2;
}

FoodHold.prototype.isGround = function() {
    return this.x1 !== this.x2 && this.y1 === this.y2;
}

FoodHold.prototype.isSlope = function() {
    return this.x1 !== this.x2 && this.y1 !== this.y2;
}

FoodHold.prototype.isWall = function() {
    return this.x1 === this.x2 && this.y1 !== this.y2;
}

FoodHold.prototype.calcY = function(x) {
    const { x1, x2, y1, y2} = this;
    return (((x - x2) * (y1 - y2)) / (x1 - x2) ) + y2;
}